<?php


class My_View_Helper_Anchor extends Zend_View_Helper_HtmlElement {

    /**
     *
     * @param string $url
     * @param string $content
     * @param array|string $attribs
     * @return string 
     */
    public function anchor($url, $content = '', $attribs = null)
    {

        if (is_array($url)) {
            $reset = isset($url[2]) ? $url[2] : false;
            $encode = isset($url[3]) ? $url[3] : false;
            $url = $this->view->url($url[0], $url[1], $reset, $encode);
        } else {
            $url = $this->view->baseUrl($url);
        }

        if (is_array($attribs)) {
            $attribs = $this->_htmlAttribs($attribs);
        } else {
            $attribs = empty($attribs) ? '' : ' '.$attribs;
        }

        if (is_array($content) && isset($content['src'])) {
            $src = $content['src'];
            $alt = isset($content['alt']) ? $this->view->translate($content['alt']) : null;
            $imgAttribs = isset($content['attribs']) ? $content['attribs'] : array();

            $content = $this->view->imgElement($src, $alt, $imgAttribs);
        }else{
           $content=$this->view->translate($content);
        }
        $content = empty($content) ? $url :$content;

        $xhtml = '<a '
                . 'href="'.$url.'"'
                . $attribs
                . '>'
                . $content
                . '</a>';

        return $xhtml;
    }

}